<template lang="">
    <div>
        <el-table :data="list" ref="form" style="width: 100%" @row-click="rowClick" highlight-current-row height="300" class="list">
            <el-table-column prop="teaNum" label="教师工号">
            </el-table-column>
            <el-table-column prop="teaName" label="教师姓名">
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
    export default {
        name: 'TeacherList',
        data() {
            return {
                list: [
                    /* {
                        "teaNum": 200021,
                        "teaName": "孙悟空"
                    },
                    {
                        "teaNum": 200021,
                        "teaName": "孙悟空"
                    },
                    {
                        "teaNum": 201021,
                        "teaName": "孙悟空"
                    },
                    {
                        "teaNum": 20001,
                        "teaName": "卢俊义"
                    },
                    {
                        "teaNum": 20031,
                        "teaName": "卢俊义"
                    },
                    {
                        "teaNum": 20021,
                        "teaName": "卢俊义"
                    },
                    {
                        "teaNum": 20011,
                        "teaName": "卢俊义"
                    }, */
                ]
            }
        },
        props:['conId'],
        methods: {
            rowClick(currentRow){           //点击后查询关于该教师的结果，同时通知CourseList查询该教师下的课程
                console.log(currentRow);
                this.$bus.$emit('teacherShowing',currentRow)

                axios({
                    method: 'GET',
                    url: '/QueResultChart/queryQueData',
                    withCredentials: true,
                    params: {
                        quedataConid : this.conId,
                        teaNum : currentRow.teaNum
                    },
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then((result) => {
                    this.$bus.$emit('teacherSelected',result.data)
                    this.$bus.$emit('teacherShowing',currentRow)
                }).catch((err) => {
                    this.$message({
                        message: '获取该教师问卷信息失败' + err.message,
                        type: 'info'
                    });
                });
            },
            getTeacherList(){          //获取教师列表
                console.log(this.conId);
                axios({
                    method: 'GET',
                    url: '/QueResultChart/queryTeacher',
                    withCredentials: true,
                    params: {
                        quedataConid : this.conId
                    },
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then((result) => {
                    this.list = result.data
                }).catch((err) => {
                    this.$message({
                        message: '拉取该问卷教师列表失败' + err.message,
                        type: 'info'
                    });
                });
            }
        },
        mounted() {
            if(this.$route.query.questionnaireType == 1){
                this.getTeacherList()
                this.$bus.$on('selectAll',()=>{
                    this.$refs.form.setCurrentRow([]);
                })
            }
        },
        beforeDestroy() {
            this.$bus.$off('selectAll')
        },
    }
</script>
<style scoped>
    .list{
        cursor: pointer;
    }
</style>